package com.ssy.lingxi.order.entity;

import com.fasterxml.jackson.annotation.JsonBackReference;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Set;

/**
 * 订单收货发货记录
 * @author 万宁
 * @version 2.0.0
 * @date 2021-07-16
 */
@Entity
@Table(schema = "public", name = "ord_delivery", indexes = {@Index(name = "ord_delivery_order_id_idx", columnList = "order_id"), @Index(name = "ord_delivery_batch_no_idx", columnList = "batchNo")})
public class OrderDeliveryDO implements Serializable {
    private static final long serialVersionUID = 8748336889476848281L;

    /**
     * 主键Id
     */
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ord_delivery_seq")
    @SequenceGenerator(sequenceName = "ord_delivery_seq", name = "ord_delivery_seq", allocationSize = 1)
    private Long id;

    /**
     * 多对一双向关联订单
     */
    @JsonBackReference
    @ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    @JoinColumn(name = "order_id")
    private OrderDO order;

    /**
     * 发货时间
     */
    @Column(columnDefinition = "timestamp")
    private LocalDateTime createTime;

    /**
     * 发货批次，同一个订单每次发货 +1
     */
    @Column
    private Integer batchNo;

    /**
     * 发货单号
     */
    @Column(columnDefinition = "varchar(20)")
    private String deliveryNo;

    /**
     * 发货地址
     */
    @Column(columnDefinition = "varchar(200)")
    private String address;

    /**
     * 物流单号
     */
    @Column(columnDefinition = "varchar(50)")
    private String logisticsNo;

    /**
     * 物流公司名称
     */
    @Column(columnDefinition = "varchar(200)")
    private String company;

    /**
     * 收货单号
     */
    @Column(columnDefinition = "varchar(20)")
    private String receiptNo;

    /**
     * 收货时间
     */
    @Column(columnDefinition = "timestamp")
    private LocalDateTime receiptTime;

    /**
     * 收货回单url地址
     */
    @Column(columnDefinition = "varchar(200)")
    private String receiveBill;

    /**
     * 收货自提码
     */
    @Column(columnDefinition = "varchar(10)")
    private String selfCode;

    /**
     * 供应商内部状态，定义在VendorInnerStatusEnum中
     */
    @Column
    private Integer vendorInnerStatus;

    /**
     * 采购商内部状态，定义在BuyerInnerStatusEnum中
     */
    @Column
    private Integer buyerInnerStatus;

    /**
     * 一对多单向关联发货商品
     */
    @OneToMany(cascade = {CascadeType.DETACH, CascadeType.REMOVE}, fetch = FetchType.EAGER)
    @JoinColumn(name = "delivery_product_id", referencedColumnName = "id")
    private Set<OrderDeliveryProductDO> deliveryProducts;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public OrderDO getOrder() {
        return order;
    }

    public void setOrder(OrderDO order) {
        this.order = order;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public Integer getBatchNo() {
        return batchNo;
    }

    public void setBatchNo(Integer batchNo) {
        this.batchNo = batchNo;
    }

    public String getDeliveryNo() {
        return deliveryNo;
    }

    public void setDeliveryNo(String deliveryNo) {
        this.deliveryNo = deliveryNo;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getLogisticsNo() {
        return logisticsNo;
    }

    public void setLogisticsNo(String logisticsNo) {
        this.logisticsNo = logisticsNo;
    }

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public String getReceiptNo() {
        return receiptNo;
    }

    public void setReceiptNo(String receiptNo) {
        this.receiptNo = receiptNo;
    }

    public LocalDateTime getReceiptTime() {
        return receiptTime;
    }

    public void setReceiptTime(LocalDateTime receiptTime) {
        this.receiptTime = receiptTime;
    }

    public String getReceiveBill() {
        return receiveBill;
    }

    public void setReceiveBill(String receiveBill) {
        this.receiveBill = receiveBill;
    }

    public String getSelfCode() {
        return selfCode;
    }

    public void setSelfCode(String selfCode) {
        this.selfCode = selfCode;
    }

    public Integer getVendorInnerStatus() {
        return vendorInnerStatus;
    }

    public void setVendorInnerStatus(Integer vendorInnerStatus) {
        this.vendorInnerStatus = vendorInnerStatus;
    }

    public Integer getBuyerInnerStatus() {
        return buyerInnerStatus;
    }

    public void setBuyerInnerStatus(Integer buyerInnerStatus) {
        this.buyerInnerStatus = buyerInnerStatus;
    }

    public Set<OrderDeliveryProductDO> getDeliveryProducts() {
        return deliveryProducts;
    }

    public void setDeliveryProducts(Set<OrderDeliveryProductDO> deliveryProducts) {
        this.deliveryProducts = deliveryProducts;
    }
}
